package com.security.door.Interceptor;

import com.alibaba.fastjson.JSON;
import com.security.door.utils.AuthJwt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Component
public class loginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest httpRequest, HttpServletResponse httpResponse, Object o) throws Exception {
      /*  if (httpRequest.getMethod().equals("OPTIONS")){
            httpResponse.setStatus(HttpServletResponse.SC_OK);
            return true;
        }
        httpResponse.setCharacterEncoding("utf-8");
        String token = httpRequest.getHeader("token");
        if (null == token)
            token = httpRequest.getParameter("token");
        if (token != null) {
            boolean result = AuthJwt.verify(token);
            if (result) {
                return true;
            }
        }
        httpResponse.setCharacterEncoding("utf-8");
        httpResponse.setHeader("Content-Type", "application/json");
        Map<String, Object> result = new HashMap<>();
        result.put("code", 100);
        result.put("message", "认证失败");
        httpResponse.getWriter().write(JSON.toJSONString(result));
        return false;*/
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}